package com.zhoug.zmui3demo.ui;

import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.NumberPicker;

import com.zhoug.common3.compat.NumberPickerCompat;
import com.zhoug.common3.utils.ResourceUtils;
import com.zhoug.common3.utils.ViewUtils;
import com.zhoug.zmui3.ZMUINumberPicker;
import com.zhoug.zmui3demo.R;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

/**
 * {@link com.zhoug.zmui3.ZMUINumberPicker}
 *
 * @Author 35574
 * @Date 2022/3/7
 * @Description
 */
public class NumberPickerActivity extends AppCompatActivity {
    private static final String TAG = ">>>NumberPickerActivity";
    private int mTextColorIndex;
    private int mTextSizeIndex;
    private int mDividerColorIndex;
    private int mDividerHeightIndex;
    private  int[] colors ;
    private  int[] textSizes;
    private  int[] heights ;


    private ZMUINumberPicker zmuiNumberPicker1;
    private NumberPicker numberPicker;
    private Button btnTextColor;
    private Button btnTextSize;
    private Button btnDivider;
    private Button btnDividerHeight;
    private ViewGroup containerContent;
    private ViewGroup root;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.zmui_number_pick_activity);
        zmuiNumberPicker1 = findViewById(R.id.ZMUINumberPicker1);
        numberPicker = findViewById(R.id.numberPicker);
        btnTextColor = findViewById(R.id.btn_textColor);
        btnTextSize = findViewById(R.id.btn_textSize);
        btnDivider = findViewById(R.id.btn_divider);
        btnDividerHeight = findViewById(R.id.btn_dividerHeight);
        containerContent = findViewById(R.id.container_content);
        root = findViewById(R.id.root);
         colors = new int[]{Color.parseColor("#333333"), ContextCompat.getColor(this, R.color.colorPrimaryDark),Color.RED};
         textSizes = new int[]{ResourceUtils.spTopx(14),ResourceUtils.spTopx(20),ResourceUtils.spTopx(10)};
         heights = new int[]{ResourceUtils.dpTopx(1),ResourceUtils.dpTopx(3),ResourceUtils.dpTopx(5)};

        int minValue = 2000;
        int maxValue = 2300;
        int endIndex = maxValue - minValue;
        String[] years = new String[endIndex + 1];
        for (int i = 0; i <= endIndex; i++) {
            years[i] = (minValue + i) + "";
        }

        zmuiNumberPicker1.setDisplayedValues(null);
        zmuiNumberPicker1.setMinValue(minValue);
        zmuiNumberPicker1.setMaxValue(maxValue);
        zmuiNumberPicker1.setDisplayedValues(years);

        numberPicker.setDisplayedValues(null);
        numberPicker.setMinValue(minValue);
        numberPicker.setMaxValue(maxValue);
        numberPicker.setDisplayedValues(years);


        btnTextColor.setOnClickListener(v -> {
            mTextColorIndex++;
            if(mTextColorIndex>=colors.length){
                mTextColorIndex=0;
            }
            int color=colors[mTextColorIndex];
            ViewUtils.findView(root, NumberPicker.class,true, view -> NumberPickerCompat.setTextColor(view, color));
        });
        btnTextSize.setOnClickListener(v -> {
            mTextSizeIndex++;
            if(mTextSizeIndex>=textSizes.length){
                mTextSizeIndex=0;
            }
            int textSize=textSizes[mTextSizeIndex];
            ViewUtils.findView(root, NumberPicker.class,true, view -> NumberPickerCompat.setTextSize(view, textSize));
        });

        btnDivider.setOnClickListener(v -> {
            mDividerColorIndex++;
            if(mDividerColorIndex>=colors.length){
                mDividerColorIndex=0;
            }
            int color=colors[mDividerColorIndex];
            ViewUtils.findView(root, NumberPicker.class,true, view -> NumberPickerCompat.setSelectionDivider(view, color));

        });

        btnDividerHeight.setOnClickListener(v -> {
            mDividerHeightIndex++;
            if(mDividerHeightIndex>=heights.length){
                mDividerHeightIndex=0;
            }
            int height=heights[mDividerHeightIndex];
            ViewUtils.findView(root, NumberPicker.class,true, view -> NumberPickerCompat.setSelectionDividerHeight(view, height));

        });
    }


}
